﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <string>
using namespace std;

class Phone
{
public:
	Phone()
	{
		cout << "Phone的默认构造函数调用！" << endl;
	}
	Phone(string name)
	{
		cout << "Phone的有参构造调用！" << endl;
		m_PhoneName = name;
	}
	~Phone()
	{
		cout << "Phone的析构函数调用！" << endl;
	}

	string m_PhoneName;
};
class Game
{
public:
	Game()
	{
		cout << "Game的默认构造函数调用！" << endl;
	}
	Game(string name)
	{
		cout << "Game的有参构造调用！" << endl;
		m_GameName = name;
	}
	~Game()
	{
		cout << "Game的析构函数调用！" << endl;
	}

	string m_GameName;
};
class PersonObject
{
public:
	PersonObject()
	{
		cout << "PersonObject的默认构造函数调用！" << endl;
	}
	/*PersonObject(string name)
	{
		m_Name = name;
	}*/
	PersonObject(string name, string phoneName, string gameName) :m_Name(name), m_Phone(phoneName), m_Game(gameName)
	{
		cout << "PersonObject的有参构造调用！" << endl;
	}

	void playGame()
	{
		cout << m_Name << "拿着《" << m_Phone.m_PhoneName << "》牌手机，玩着《" << m_Game.m_GameName << "》游戏！" << endl;
	}

	~PersonObject()
	{
		cout << "PersonObject的析构函数调用！" << endl;
	}

	//1.姓名，手机，游戏；
	string m_Name;
	Phone m_Phone;
	Game m_Game;
};
//2.类对象作为类成员时，构造顺序是：先将类对象一一构造，然后构造自己；析构的顺序反过来；
void testClassObject()
{
	//PersonObject p;
	//p.m_Phone.m_PhoneName = "小米";
	//p.m_Game.m_GameName = "王者荣耀";

	PersonObject p2("达芬奇", "华为", "原神");
	p2.playGame();
	/*
	* Phone的有参构造调用！
	* Game的有参构造调用！
	* PersonObject的有参构造调用！
	* 达芬奇拿着《华为》牌手机，玩着《原神》游戏！
	* PersonObject的析构函数调用！
	* Game的析构函数调用！
	* Phone的析构函数调用！
	*/
}

//main263：类对象作为类成员
int main263()
{
	testClassObject();
	/*
	* Phone的默认构造函数调用！
	* Game的默认构造函数调用！
	* PersonObject的默认构造函数调用！
	* PersonObject的析构函数调用！
	* Game的析构函数调用！
	* Phone的析构函数调用！
	*/

	system("pause");
	return EXIT_SUCCESS;
}